package com.jy.reservations.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jy.common.annotation.Log;
import com.jy.common.core.controller.BaseController;
import com.jy.common.core.domain.AjaxResult;
import com.jy.common.core.page.TableDataInfo;
import com.jy.common.enums.BusinessType;
import com.jy.common.utils.poi.ExcelUtil;
import com.jy.reservations.domain.Reservations;
import com.jy.reservations.service.IReservationsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 图书预留Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/reservations/reservations")
public class ReservationsController extends BaseController
{
    @Autowired
    private IReservationsService reservationsService;

    /**
     * 查询图书预留列表
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:list')")
    @GetMapping("/list")
    public TableDataInfo list(Reservations reservations)
    {
        startPage();
        List<Reservations> list = reservationsService.selectReservationsList(reservations);
        return getDataTable(list);
    }

    /**
     * 导出图书预留列表
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:export')")
    @Log(title = "图书预留", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reservations reservations)
    {
        List<Reservations> list = reservationsService.selectReservationsList(reservations);
        ExcelUtil<Reservations> util = new ExcelUtil<Reservations>(Reservations.class);
        util.exportExcel(response, list, "图书预留数据");
    }

    /**
     * 获取图书预留详细信息
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:query')")
    @GetMapping(value = "/{reservationId}")
    public AjaxResult getInfo(@PathVariable("reservationId") Long reservationId)
    {
        return success(reservationsService.selectReservationsByReservationId(reservationId));
    }

    /**
     * 新增图书预留
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:add')")
    @Log(title = "图书预留", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reservations reservations)
    {
        return toAjax(reservationsService.insertReservations(reservations));
    }

    /**
     * 修改图书预留
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:edit')")
    @Log(title = "图书预留", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reservations reservations)
    {
        return toAjax(reservationsService.updateReservations(reservations));
    }

    /**
     * 删除图书预留
     */
    @PreAuthorize("@ss.hasPermi('reservations:reservations:remove')")
    @Log(title = "图书预留", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reservationIds}")
    public AjaxResult remove(@PathVariable Long[] reservationIds)
    {
        return toAjax(reservationsService.deleteReservationsByReservationIds(reservationIds));
    }
}
